import {
    fetchDeviceInfo
} from '@/services/device';
import {
    getParams, logger
} from '@/utils/util'

const componentMappings = new Map([
    [
        8, {
            'A666G': 'bpgauge-component',
            'X2A': 'bpgauge-component',
            'YE620AR': 'bpgauge-component'
        }
    ],
    [
        9, {
            'G777G': 'glucometer-component',
            'T808': 'glucometer-component',
            '302G': 'glucometer-component'
        }
    ],
    [
        2, {
            'DD_T': 'tyfall-component'
        }
    ],
    [
        13, {
            'RC_T': 'existence-component'
        }
    ],
    [
        14, {
            'SM_T': 'sleep-component'
        }
    ]
])

Page({
    data: {
        currentComponent: null
    },
    async onLoad(options) {
        const {
            device_imei,
            device_type,
            product_type
        } = getParams(options.params);
        const res = await fetchDeviceInfo({
            device_imei
        });
        this.setData({
            currentComponent: componentMappings.get(device_type)[product_type],
            deviceInfo: res.data
        })
    }
});